<div class="formulir">
<form action="<?php echo base_url();?>rajut" method="post" id="rajut">
<span class="width300">
No. Reg <input type="text" name="no" readonly="readonly"/>
</span>
<br/>
<span class="width300"> 
Tanggal <input id="datePicker" type="date" name="date" />
</span>
<span class="width300"> 
Shift <input type="number" name="shift" value="1" /> 
</span>
<span class="width300"> Kelompok
<select id="groupKaryawan" onchange="updateKaryawan()">
	<option value="#" selected="selected">#</option>
	<?php
	foreach ($query_kelompok->result() as $row):
	?>
	<option value="<?php echo $row->kelompok;?>"><?php echo $row->kelompok;?></option>
	<?php
	endforeach;
	?>
</select>
</span>
<hr />
<?php
$i=1;
for($i=1;$i<=3;$i++):
?>
<div id="pegawai<?php echo $i; ?>" class="pegawai">
	<span class="width300"> Nama <?php echo $i; ?> 
	<select id="namaKaryawan" form="rajut" name="nama[]" onchange="setValue()">
		<option value="" selected="selected"></option>
		<?php
		foreach ($query_karyawan->result() as $row):
		?>
		<option value="<?php echo $row->kode;?>"><?php echo $row->nama;?></option>
		<?php
		endforeach;
		?>
	</select>
	</span>
	<span class="width100"> <input type="checkbox" name="hadir[]" value="Hadir" checked="checked"> Hadir </span>
	<span class="width300">
	<span> Gaji <?php echo $i; ?> </span>
	<span> <input type="text" name="gaji[]" value="0" /> </span>
	</span>
	<span class="width300">
	<span> Teknisi <?php echo $i; ?> </span>
	<span> <input type="text" name="teknisi[]" value="0" /> </span>
	</span>
</div>
<?php
endfor;
?>
<hr/>
<label for="keterangan">Keterangan</label>
<input type="text" name="keterangan" class="width95p"/>
<hr/>
<div class="table">
	<div id="header">
		<b>
		<span class="width300">Nama</span>
		<span class="width300">Nomor Laporan</span>
		<span class="width200">Rajut</span>
		</b>
	</div>
	<div id="body">
		<span class="width300">
		<select id="group" form="rajut" name="namarajut[]">
			<option value="" selected="selected">#</option>
			<?php
			foreach ($query_barang->result() as $row):
			?>
			<option value="<?php echo $row->kode;?>" label="<?php echo $row->nama;?>"><?php echo $row->kelompok;?></option>
			<?php
			endforeach;
			?>
		</select>
		</span>
		<span class="width300"> <input type="text" name="nolap[]" /> </span>
		<span class="width200"> <input type="text" name="jumlahrajut[]" value="0" class="right value" onchange="updateSum()" /> </span>
		<br/>
	</div>
	<div id="footer">
		<b>
		<span class="width800">Total</span>
		<span class="width100" id="value">0</span>
		</b>
		<input type="button" id="addRow" onclick="insertRow()" value="Tambah Baris" />
	</div>
</div>
<hr/>
<input type="submit" class="submit" value="Tambah" />
</form>
</div>
<script type="text/javascript">
// Set Date
document.getElementById("datePicker").valueAsDate  = new Date();
// Other function
function insertRow()
{
	$( ".table #body" ).append( '<span class="width300"><select id="group" form="rajut" name="namarajut[]"><option value="" selected="selected">#</option><?php	foreach ($query_barang->result() as $row): ?><option value="<?php echo $row->kode;?>"><?php echo $row->nama;?></option>	<?php endforeach; ?> </select></span> <span class="width300"> <input type="text" name="nolap[]" /> </span>	<span class="width200"> <input type="text" name="jumlahrajut[]" value="0" class="right value" onchange="updateSum()" /> </span> <br/>' );
}
function updateSum()
{
	$sum = 0;
	$( ".value" ).each(function() {
	  $sum += parseInt($( this ).val());
	});
	$("#value").html($sum);
}
function updateKaryawan()
{
	$value = $("#groupKaryawan").val();
	$( "#namaKaryawan" ).each(function() {
		$(this).each(function() {
			$v2 = $( this ).val();
			alert($v2);
		})		
	});
	//alert($value);
}
</script>